﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml.Serialization;

namespace EpiNEXT.Core
{
    [Serializable()]
    public class CodeListValue
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public CodeListValue()
        {
            IsOtherValue = false;
            TargetValues = new ObservableCollection<CodeListTargetValue>();
            IsOtherValue = false;
            Culture = String.Empty;
        }

        [XmlElement("Store")]
        public string Store { get; set; }

        [XmlElement("Display")]
        public string Display { get; set; }

        [XmlElement]
        public bool IsOtherValue { get; set; }

        [XmlIgnore]
        internal CodeList Owner { get; set; }

        /// <summary>
        /// The list of values
        /// </summary>
        [XmlArray("TargetValues")]
        [XmlArrayItem("TV", typeof(CodeListTargetValue))]
        public ObservableCollection<CodeListTargetValue> TargetValues { get; set; }

        // TODO: move to view model
        [XmlIgnore]
        public string DisplayUI
        {
            get
            {
                CodeList codeList = this.Owner;
                if (codeList.Concatenate)
                {
                    return this.Store + codeList.Separator + this.Display;
                }
                else
                {
                    return Display;
                }
            }
        }

        [XmlElement("Culture")]
        public string Culture { get; set; }

        [XmlElement("SourceValue")]
        public string SourceValue { get; set; }
    }
}
